import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import Cookies from 'js-cookie'
import VueParticles  from 'vue-particles'
import './plugins/element.js'
// 导入全局样式表
import './assets/css/global.css'
// 阿里图标库
import './assets/icon/icon.css'
// 导入封装好的分页
import Pagination from '@/components/Pagination'
import Download from '@/common/js/download'
// 文件上传组件
import FileUpload from "@/components/FileUpload"
// excel上传组件
import ExcelUpload from "@/components/ExcelUpload"
// 图片上传组件
import ImageUpload from "@/components/ImageUpload"
import orderImageUpload from "@/components/orderImageUpload"
import { resetForm,parseTime } from "@/utils/ruoyi";
import DictTag from "@/components/DictTag"
// 字典数据组件
import DictData from '@/components/DictData'
Vue.component('pagination',Pagination)
Vue.component('FileUpload', FileUpload)
Vue.component('ExcelUpload', ExcelUpload)
Vue.component('ImageUpload', ImageUpload)
Vue.component('orderImageUpload', orderImageUpload)
Vue.component('DictTag', DictTag)
Vue.use(VueParticles)
DictData.install()
// axios.defaults.baseURL = process.env.VUE_APP_BASE_API
Vue.prototype.$cookie = Cookies; 

Vue.prototype.$download = Download;
Vue.prototype.resetForm = resetForm
Vue.prototype.parseTime = parseTime
Vue.config.productionTip = false
router.afterEach(function (to) {
  window.scrollTo(0, 0)
  })
//路由全局钩子
router.beforeEach((to, from, next) => {
  let token = Cookies.get('token');
  axios.defaults.headers.get['token'] = token;
  axios.defaults.headers.post['token'] = token;
  let contentText = to.path.includes('/index')
  if (contentText) {
    next()
    window.scrollTo(0,0)
  } else {
  
          if (token || to.path == '/login') {
              next()
          } else {
              next('/login')
          }
  }

})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
